#!/usr/bin/env python3
# -*- coding=utf-8 -*-

import sys
import os
import time


class Common(object):
    """
    公共方法
    """

    def __init__(self):
        self.param_dict = {}

    def get_para_from_jenkins(self):
        para_from_jen = sys.argv
        self.param_dict['testSuite'] = para_from_jen[1]

        for pkv in para_from_jen[2:]:
            pkv_list = pkv.split("=")
            self.param_dict[pkv_list[0]] = pkv_list[1]
        return self.param_dict

    def getTags(self, param_dict):
        """
        获取标签
        """
        self.param_dict = param_dict
        test_suite = self.param_dict.get("testSuite")
        selenium_node_list = self.param_dict.get("selenium_node").split(",")
        print(test_suite)
        print(selenium_node_list)
        return test_suite, selenium_node_list

    def clean_logs(self):
        """
        清除日志
        """
        dir_list = []
        path = os.getcwd() + "/resultDir/"
        files = os.listdir("./resultDir")  # 获取指定目录下的所有文件夹和文件
        for file in files:
            file = path + file
            if os.path.isdir(file):
                dir_list.append(file)

    def get_curtime(self):
        return time.strftime("%Y%m%d%H%M%S", time.localtime())
